package fair.controllerMobile;

import com.alibaba.dubbo.config.annotation.Reference;
import fair.constant.MessageConstant;
import fair.entity.Result;
import fair.pojo.Setmeal;
import fair.service.SetMealService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fair_wu
 * @version v1.0
 * @package fair.comtroller
 * @date 2021-01-27 下午 19:16
 */

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference
    private SetMealService service;

    @GetMapping("/getSetmeal")
    public Result getSetmeal(){
        try {
            List<Setmeal>list =  service.findAll();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    @GetMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal = service.findById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
